{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fnoticeeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>系统公告列表</h5>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div  class="col-sm-2" style="width: 130px">
                        <div class="input-group" >
                            <a href="{:url('add_notice')}"><button class="btn btn-outline btn-primary" type="button">添加系统公告</button></a>
                        </div>
                    </div>
                    <form name="noticemin_list_sea" class="form-search" method="post" action="{:url('index')}">
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" id="key" class="form-control" name="key" value="{$val}" placeholder="输入需查询系统公告标题" />
                                <span class="input-group-btn">
                                    <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="example-wrap">
                <div class="example">
                    <table class="table table-bordered table-hover">
                        <thenotice>
                        <tr class="long-tr">
                            <th>ID</th>
                            <th>标题</th>

                            <th>添加时间</th>
                            <th width="15%">操作</th>
                        </tr>
                        </thenotice>
                        <script id="arlist" type="text/html">
                            {{# for(var i=0;i<d.length;i++){  }}

                            <tr class="long-td">
                                <td>{{d[i].id}}</td>
                                <td>{{d[i].title}}</td>
                                <td>{{d[i].addtime1}}</td>
                                <td>
                                    <a href="javascript:;" onclick="edit_notice({{d[i].id}})" class="btn btn-primary btn-xs btn-outline">
                                        <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                                    <a href="javascript:;" onclick="del_notice({{d[i].id}})" class="btn btn-danger btn-xs btn-outline">
                                        <i class="fa fa-trash-o"></i> 删除</a>
                                </td>
                            </tr>
                            {{# } }}
                        </script>
                        <tbody id="article_list"></tbody>
                    </table>
                    <div id="AjaxPage" style=" text-align: right;"></div>
                    <div id="allpage" style=" text-align: right;"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>

<!-- 加载动画 -->
<div class="spiner-example">
    <div class="sk-spinner sk-spinner-three-bounce">
        <div class="sk-bounce1"></div>
        <div class="sk-bounce2"></div>
        <div class="sk-bounce3"></div>
    </div>
</div>

{include file="public/footer" /}

<script type="text/javascript">

    /**
     * [Ajaxpage laypage分页]
     * @param {[type]} curr [当前页]
     * @Author[田建龙 864491238@qq.com]
     */
    function Ajaxpage(curr){

        var key=$('#key').val();
        $.getJSON('{:url("notice/index")}', {
            page: curr || 1,key:key
        }, function(data){      //data是后台返回过来的JSON数据

            $(".spiner-example").css('display','none'); //数据加载完关闭动画
            if(data==''){
                $("#article_list").html('<td colspan="20" style="pnoticeding-top:10px;pnoticeding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
            }else{
                article_list(data); //模板赋值
                laypage({
                    cont: $('#AjaxPage'),//容器。值支持id名、原生dom对象，jquery对象,
                    pages:'{$allpage}',//总页数
                    skip: true,//是否开启跳页
                    skin: '#1AB5B7',//分页组件颜色
                    curr: curr || 1,
                    groups: 3,//连续显示分页数
                    jump: function(obj, first){

                        if(!first){
                            Ajaxpage(obj.curr)
                        }
                        $('#allpage').html('第'+ obj.curr +'页，共'+ obj.pages +'页');
                    }
                });
            }
        });
    }

    Ajaxpage();

    /**
     * [article_list 接收异步获取的数据渲染到模板]
     * @Author[田建龙 864491238@qq.com]
     */
    function article_list(list){

        var tpl = document.getElementById('arlist').innerHTML;
        laytpl(tpl).render(list, function(html){
            document.getElementById('article_list').innerHTML = html;
        });
    }


    /**
     * [edit_notice 编辑系统公告]
     * @Author[田建龙 864491238@qq.com]
     */
    function edit_notice(id){

        location.href = './edit_notice/id/'+id+'.html';
    }


    /**
     * [del_notice 删除系统公告]
     * @Author[田建龙 864491238@qq.com]
     */
    function del_notice(id){
        layer.confirm('确认删除此系统公告?', {icon: 3, title:'提示'}, function(index){
            $.getJSON('./del_notice', {'id' : id}, function(res){
                if(res.code == 1){
                    layer.msg(res.msg,{icon:1,time:1500,shnoticee: 0.1});
                    Ajaxpage(1,5)
                }else{
                    layer.msg(res.msg,{icon:0,time:1500,shnoticee: 0.1});
                }
            });

            layer.close(index);
        })

    }


    /**
     * [notice_state 系统公告状态]
     * @Author[田建龙 864491238@qq.com]
     */
    function notice_state(val){
        $.post('{:url("notice_state")}',
                {id:val},
                function(data){

                    if(data.code==1){
                        var a='<span class="label label-danger">禁用</span>'
                        $('#zt'+val).html(a);
                        layer.msg(data.msg,{icon:2,time:1500,shnoticee: 0.1,});
                        return false;
                    }else{
                        var b='<span class="label label-info">开启</span>'
                        $('#zt'+val).html(b);
                        layer.msg(data.msg,{icon:1,time:1500,shnoticee: 0.1,});
                        return false;
                    }
                });
        return false;
    }
</script>
</body>
</html>